package cn.thoughtworks.school.contract;

import cn.thoughtworks.school.usercenter.Application;
import cn.thoughtworks.school.usercenter.controllers.EmailResetController;
import cn.thoughtworks.school.usercenter.repositories.EmailResetRepository;
import cn.thoughtworks.school.usercenter.repositories.UserRepository;
import cn.thoughtworks.school.usercenter.services.SendEmailService;
import com.github.database.rider.core.api.configuration.DBUnit;
import com.github.database.rider.core.api.dataset.DataSet;
import com.github.database.rider.spring.api.DBRider;
import io.restassured.module.mockmvc.RestAssuredMockMvc;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.HttpStatus;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder;

import java.io.IOException;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@Ignore
@SpringBootTest(classes = Application.class)
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@Slf4j
@DBRider
@DBUnit(caseSensitiveTableNames = true)
@DataSet(value = "emailReset.yml")
public class EmailResetBase {

    @MockBean
    SendEmailService sendEmailService;

    @Autowired
    UserRepository userRepository;

    @Autowired
    EmailResetRepository emailResetRepository;

    @Autowired
    private EmailResetController emailResetController;


    @Before
    public void setup() throws IOException {
        HttpResponse httpResponse = mock(HttpResponse.class);
        StatusLine statusLine = mock(StatusLine.class);
        when(httpResponse.getStatusLine()).thenReturn(statusLine);
        when(httpResponse.getStatusLine().getStatusCode()).thenReturn(HttpStatus.OK.value());
        when(sendEmailService.sendEmail(anyString(), anyString(), anyString())).thenReturn(httpResponse);
        StandaloneMockMvcBuilder standaloneMockMvcBuilder = MockMvcBuilders.standaloneSetup(emailResetController);
        RestAssuredMockMvc.standaloneSetup(standaloneMockMvcBuilder);
    }
}
